package com.example.stumanager.admin;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.stumanager.R;
import com.example.stumanager.database.UserSql;
import com.example.stumanager.entity.UserEntity;

/**
 * 修改学生信息
 */
public class AdminModifyStudentsPage extends AppCompatActivity {

    EditText number, name, passWord, dormitory, grade;
    Button add, c;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.admin_modify_students_page);

        c = findViewById(R.id.re);
        add = findViewById(R.id.add);

        number = findViewById(R.id.number);
        name = findViewById(R.id.name);
        passWord = findViewById(R.id.passWord);
        grade = findViewById(R.id.grade);
        dormitory = findViewById(R.id.dormitory);

        UserSql db = new UserSql(this);
        c.setOnClickListener(view -> finish());
        add.setOnClickListener(view -> {

            UserEntity u = new UserEntity(number.getText().toString(), name.getText().toString(), passWord.getText().toString(),
                    dormitory.getText().toString(), grade.getText().toString());
            if (db.change(u)) {
                Toast.makeText(AdminModifyStudentsPage.this, "修改成功", Toast.LENGTH_SHORT).show();
                finish();
            } else {
                Toast.makeText(AdminModifyStudentsPage.this, "修改失败，学号或不存在", Toast.LENGTH_SHORT).show();
            }
        });
    }
}